// 根据后台skus数据得到可走路径字典对象
// js算法库 https://github.com/trekhleb/javascript-algorithms
// 幂集算法 https://raw.githubusercontent.com/trekhleb/javascript-algorithms/master/src/algorithms/sets/power-set/bwPowerSet.js

export default function bwPowerSet(originalSet) {
	const subSets = [];
	const numberOfCombinations = 2 ** originalSet.length;

	for (let combinationIndex = 0; combinationIndex < numberOfCombinations; combinationIndex += 1) {
		const subSet = [];

		for (let setElementIndex = 0; setElementIndex < originalSet.length; setElementIndex += 1) {
			if (combinationIndex & (1 << setElementIndex)) {
				subSet.push(originalSet[setElementIndex]);
			}
		}

		subSets.push(subSet);
	}

	return subSets;
}
